<?php

class baklalar extends CI_Model
{
	
	protected $tableName = "baklalar";
	protected $query;
	protected $count;
	protected $slug;
	
	public function __construct()
	{
		parent::__construct();
		
		
	}
	
	public function al($slug = "")
	{
		if($slug == "")
		{
			show_404();
		}
		else
		{
			$this->slug = $slug;
			$this->query = $this->db->get_where($this->tableName, array("slug"=>$this->slug));
			
			if($this->query->num_rows() > 0)
			{
				return $this->query->row();
			}
			else
			{
				show_404();
			}
		}
		
	}
	
	public function son($count)
	{
		if($count == "")
		{
			show_error("Baklalar alınırken bir sorun oluştu.");
		}
		else
		{
			$this->count = $count;
			$this->db->order_by("id","desc");
			$this->db->limit($this->count);
			$this->query = $this->db->get_where($this->tableName, array("durum"=>2));
			
			if($this->query->num_rows() > 0)
			{
				return $this->query->result();
			}
			else
			{
				return false;
			}
		}
	}
	
	public function merak_edilenler($count, $order = "cevap_sayisi")
	{
		if($count == "")
		{
			show_error("Baklalar alınırken bir sorun oluştu.");
		}
		else
		{
			$this->count = $count;
			$this->db->order_by($order,"desc");
			$this->db->limit($this->count);
			$this->query = $this->db->get_where($this->tableName, array("durum"=>2));
			
			if($this->query->num_rows() > 0)
			{
				return $this->query->result();
			}
			else
			{
				return false;
			}
		}
	}
}

?>